const spStr: RegExp = /[^a-zA-Z0-9]/g;
const phoneNum: RegExp = /^1[34578]\d{9}$/;
const regex = /^[A-Za-z0-9_?]+$/;
export const accountValidation = (rule: any, value: any, callback: any) => {
  if ((value && value.length < 4) || (value && value.length > 24)) {
    callback(new Error("账号长度不小于4且不大于24"));
  } else if (spStr.test(value)) {
    callback(new Error("账号不能存在特殊字符"));
  } else {
    callback();
  }
};

export const passwordValidation = (t:any) => {
    return (rule: any, value: any, callback: any)=> {
      if (!regex.test(value)) {
        callback(t("signUp.sp"));
      } else {
        callback();
      }
    }
};

export const phoneNumberValidation = (rule: any, value: any, callback: any) => {
  if (value && value.length !== 11) {
    callback(new Error("手机号格式错误"));
  } else if (!phoneNum.test(value)) {
    callback(new Error("手机号格式错误"));
  } else {
    callback();
  }
};
export const phoneNumberValidationForPre = (rule: any, value: any, callback: any) => {
  if (value && value.length !== 11) {
    callback(new Error("手机号格式错误"));
  } else if (!phoneNum.test(value)) {
    callback();
  } else {
    callback();
  }
};
export const mailValid = (t:any) => {
  return (rule: any, value: any, callback: any)=> {
    const emailRegex = /^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$/;
    if (emailRegex.test(value)) {
      callback();
    } else {
      callback(t("signUp.invalidMail"));
    }
  }

};


